package com.xinruke.hostels.reservation.controller;

import com.xinruke.hostels.common.controller.BaseController;
import com.xinruke.hostels.common.vo.ResultVO;
import com.xinruke.hostels.common.vo.query.RowsDataVO;
import com.xinruke.hostels.reservation.interfaces.dto.*;
import com.xinruke.hostels.reservation.service.CartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author GuoZheng
 * @ClassName CartgoController
 * @date：2019/6/13
 * @version: V1.0.0
 * @description：询价车管理
 */
@RestController
@RequestMapping("/cart/")
@Api(tags = "询价车管理")
@ApiIgnore
public class CartController extends BaseController {
    @Resource
    private CartService cartService;


    /**
     * 添加询价车
     *
     * @param params
     * @return
     */
    @PostMapping("add")
    @ApiOperation("添加询价车")
    public ResultVO addCart(@Valid @RequestBody CartAddDto params) {
        ResultVO resultVO = ResultVO.fail();
        cartService.addCart(params);
        resultVO.setCode(ResultVO.SUCCESS);
        resultVO.setMessage("操作成功");
        return resultVO;
    }

    /**
     * 更新询价车商品（修改购物商品数量）暂时不用
     *
     * @param params
     * @return
     */
    @PostMapping("update")
    @ApiIgnore
    @ApiOperation("更新询价车商品（修改购物商品数量）")
    public ResultVO addCart(@Valid @RequestBody CartUpdateDto params) {
        ResultVO resultVO = ResultVO.fail();
        cartService.updateCart(params);
        resultVO.setCode(ResultVO.SUCCESS);
        resultVO.setMessage("操作成功");
        return resultVO;
    }

    /**
     * 获取询价车信息
     * 查询类型1：-个人预订，2-会议预订
     *
     * @param params
     * @return
     */
    @PostMapping("data")
    @ApiOperation("获取询价车信息")
    public ResultVO<RowsDataVO<CartQuryResultDto>> cartData(@Valid @RequestBody CartQuryDto params) {
        ResultVO<RowsDataVO<CartQuryResultDto>> resultVO = ResultVO.fail();
        RowsDataVO<CartQuryResultDto> data = cartService.cartData(params);
        resultVO.setCode(ResultVO.SUCCESS);
        resultVO.setMessage("操作成功");
        resultVO.setData(data);
        return resultVO;
    }

    /**
     * 删除询价车商品
     *
     * @param params
     * @return
     */
    @PostMapping("delCartGoods")
    @ApiOperation("删除询价车商品")
    public ResultVO delCartGoods(@Valid @RequestBody CartClearDto params) {
        ResultVO resultVO = ResultVO.fail();
        cartService.delCartGoods(params);
        resultVO.setCode(ResultVO.SUCCESS);
        resultVO.setMessage("操作成功");
        return resultVO;
    }

    /**
     * 清空询价车
     *
     * @param params
     * @return
     */
    @PostMapping("clearCart")
    @ApiOperation("清空询价车")
    public ResultVO clearCart(@Valid @RequestBody CartClearDto params) {
        ResultVO resultVO = ResultVO.fail();
        cartService.clearCartGoods(params);
        resultVO.setCode(ResultVO.SUCCESS);
        resultVO.setMessage("操作成功");
        return resultVO;
    }

    /**
     * 获取询价车种类总数
     *
     * @param params
     * @return
     */
    @PostMapping("cartGoodsCount")
    @ApiOperation("获取询价车种类总数")
    public ResultVO<Integer> cartGoodsCount(@Valid @RequestBody CartCountDto params) {
        ResultVO<Integer> resultVO = ResultVO.fail();
        Integer data = cartService.cartGoodsCount(params);
        resultVO.setCode(ResultVO.SUCCESS);
        resultVO.setMessage("操作成功");
        return resultVO;
    }

}
